package h0720;

import java.util.Arrays;
import java.util.Scanner;
import java.util.StringJoiner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 螺旋数字矩阵
 * @date 2024/7/20 12:47
 */
public class SpiralNumericalMatrix {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.close();
//      int quotient = (int) Math.ceil((double) n / m);
        //优化点
        int quotient=(n+m-1)/m;  //用这个算式直接取整。

        //确定行列。
        int row=m;
        int col=quotient;
        int[][] matrix=getMatrix(row,col);
        String[][] res = new String[row][col];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                int temp = matrix[i][j];
                if (temp<=n){
                    res[i][j]= Integer.toString(temp);
                }else {
                    res[i][j]="*";
                }
            }
        }
        for (String[] re : res) {
            StringJoiner joiner = new StringJoiner(" ");
            for (String s : re) {
                joiner.add(s);
            }
            System.out.println(joiner);
        }
    }

    private static int[][] getMatrix(int row, int col) {
        int left=0;
        int right=col-1;
        int up=0;
        int down=row-1;

        int[][] ans = new int[row][col];
        int temp=1;
        while (left<=right&&up<=down){

            for (int i = left; i <= right; i++) {
                ans[up][i]=temp;
                temp++;
            }
            up++; //下移一层
            for (int i = up; i <=down ; i++) {
                ans[i][right]=temp;
                temp++;
            }
            right--;//right左移

            if (up<=down){    //感觉这里不用等号也可以因为
                for (int i = right; i >=left ; i--) {
                    ans[down][i]=temp++;
                }
                down--; //down上移
            }
            if (left<=right){
                for (int i = down; i >=up ; i--) {
                    ans[i][left]=temp++;
                }
                left++; //left左移
            }
        }
        return ans;
    }
}
